import "babel-polyfill"
import Vue from 'vue'
import VueRouter from 'vue-router'
import '@/assets/css/pubilc.css'
import '@/assets/css/iconfont.css'
import '@/assets/css/common.css'
import router from './router'
import index from './app.vue'
import FastClick from 'fastclick'
import moment from 'dayjs'
import store from '@/store'
import utils from '../util/request'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import regular from '../util/regular'
import common from '../util/common'
import enums from '../util/enums'
import helper from '../util/helper'
import '../util/reset'
import pagination from 'component/pagination'//全局注册分页组件
import echarts from 'echarts'
import QuillEditor from 'vue-quill-editor' // 全局引入富文本框
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.bubble.css'
import 'quill/dist/quill.snow.css'
import locale from 'element-ui/lib/locale'
import i18n from './language/i18n'
import lang from 'element-ui/lib/locale/lang/en'
import langZh from 'element-ui/lib/locale/lang/zh-CN'
const langCode = localStorage.getItem('languageSet') || 'en'
locale.use(langCode === 'en' ? lang : langZh)

Vue.use(QuillEditor)
//全局注册分页组件
Vue.component('pagination', pagination)
Vue.prototype.moment = moment
Vue.prototype.request = utils
Vue.prototype.enums = enums
Vue.prototype.regular = regular
Vue.prototype.common = common
Vue.prototype.echarts = echarts
Vue.prototype.helper = helper

FastClick.attach(document.body)
Vue.use(VueRouter)
Vue.use(ElementUI);
router.beforeEach((to, from, next) => {
  let token = sessionStorage.getItem('token')
  if (to.path == "/" && token) {
    next({ path: '/articleList' });
  } else if (to.path != "/" && !token) {
    next({ path: '/' });
  } else {
    next();
  }
});
new Vue({
  el: '#index',
  router,
  store,
  i18n,
  render: v => v(index),
})
